package com.example.tiptravel.commom.base;

import android.location.LocationListener;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;

import butterknife.ButterKnife;

/**
 * Created by 45820 on 2016/11/5.
 */

public abstract class BaseActivity extends AppCompatActivity implements AMapLocationListener {


    //高德定位客户端
    protected AMapLocationClient client;
    //定位设置参数
    protected AMapLocationClientOption clientOption;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());
        //设置高德地图
        client = new AMapLocationClient(getApplicationContext());
        client.setLocationOption(getClientOption());
        client.setLocationListener(this);
        ButterKnife.bind(this);
        initView(savedInstanceState);
    }

    protected abstract int getLayout();

    protected abstract void initView(Bundle savedInstanceState);

    protected void initData() {

    }

    public AMapLocationClientOption getClientOption() {
        clientOption = new AMapLocationClientOption();
        clientOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        clientOption.setOnceLocationLatest(true);
        return clientOption;
    }

    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {

    }
}
